﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.DS
{
    public static partial class experiment
    {
        public static dynamic deleteExperiment(int eid)
        {
            var sql = new Sql.SqlDataContext();
            var e = sql.DSExperiment.FirstOrDefault(row => row.eid == eid);
            if (e == null) return new
            {
                success = false,
                msg = "实验不存在"
            };
            // Delete Problem
            sql.DSProblem.DeleteAllOnSubmit(sql.DSProblem.Where(row => row.eid == eid));

            // Delete ProblemStatistics
            sql.DSProblemStatistics.DeleteAllOnSubmit(sql.DSProblemStatistics.Where(row => row.eid == eid));

            // Delete Solve
            sql.DSSolve.DeleteAllOnSubmit(sql.DSSolve.Where(row => row.eid == eid));

            // Delete Status
            sql.DSStatus.DeleteAllOnSubmit(sql.DSStatus.Where(row => row.eid == eid));

            // Delete ExperimentSolve
            sql.DSExperimentSolve.DeleteAllOnSubmit(sql.DSExperimentSolve.Where(row => row.eid == eid));

            // Delete Experiment
            sql.DSExperiment.DeleteOnSubmit(e);
            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}
